package com.example.demo3.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo3.entity.*;
import com.example.demo3.mapper.*;
import com.example.demo3.service.HwAdsService;
import com.example.demo3.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

@Service


public class HwAdsServiceImpl implements HwAdsService {
    @Autowired
    AdsFeatuesCorrMapper adsFeatuesCorrMapper;

    @Autowired
    AdsGradeMapper adsGradeMapper;

    @Autowired
    AdsNhMapper adsNhMapper;

    @Autowired
    AdsToiletAmountMapper adsToiletAmountMapper;

    @Autowired
    AdsToiletLevelMapper adsToiletLevelMapper;

    @Autowired
    AdsToiletSmartMapper adsToiletSmartMapper;

    @Autowired
    AdsUseageMapper adsUseageMapper;

    @Override
    public Result getCorr() {
        List<AdsFeatuesCorr> list = adsFeatuesCorrMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getGrade(PageObj pageObj) {
        //扣分前十
        QueryWrapper<AdsGrade> queryWrapper = new QueryWrapper<AdsGrade>();
        queryWrapper.orderByDesc("grade")
                .last("limit" + pageObj.getSize());//通过分数进行降序排序
        List<AdsGrade> list = adsGradeMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getNh(PageObj pageObj) {
        QueryWrapper<AdsNh> queryWrapper = new QueryWrapper<AdsNh>();
        queryWrapper.orderByDesc("nh_sum")//臭味字段降序
                .last("limit" + pageObj.getSize());//用户输入行数进行查询
        List<AdsNh> list = adsNhMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getAmount() {
        List<AdsToiletAmount> list = adsToiletAmountMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getLevel() {
        List<AdsToiletLevel> list = adsToiletLevelMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getSmart() {
        List<AdsToiletSmart> list = adsToiletSmartMapper.selectList(null);
        return new Result(200, "查询成功", list);
    }

    @Override
    public Result getUsage(PageObj pageObj) {
        //创建分页对象
        Page<AdsUseage> page = new Page<AdsUseage>(pageObj.getPage(), pageObj.getSize());
        ;
        //条目没有
        adsUseageMapper.selectPage(page, null);
        //查询数据
        List<AdsUseage> list = page.getRecords();
        long total = page.getTotal();
        HashMap<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("list", list);
        hashMap.put("total", total);
        return new Result(200, "查询成功", hashMap);
    }
}



